package future;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * 描述
 *
 * @author codefish
 * @version 1.0
 * @date 2022/07/23 下午 02:23
 */
public class FutureTaskThreadPool {
    public static void main(String[] args) {

        ExecutorService pool = Executors.newFixedThreadPool(3);
        pool.submit(FutureTaskThreadPool::task1);
        pool.submit(FutureTaskThreadPool::task2);
        long stime = System.currentTimeMillis();

        task3();
        long etime = System.currentTimeMillis();
        System.out.println("---costTime：" + (etime - stime) + "ms");
        pool.shutdown();
    }

    public static void task1() {
        try { TimeUnit.MILLISECONDS.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); }
    }

    public static void task2() {
        try {
            TimeUnit.MILLISECONDS.sleep(600);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void task3() {
        try {
            TimeUnit.MILLISECONDS.sleep(400);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}
